package cn.ham.ms.service.impl;

import cn.ham.ms.annotation.MasterDb;
import cn.ham.ms.annotation.SlaveDb;
import cn.ham.ms.entity.User;
import cn.ham.ms.mapper.UserMapper;
import cn.ham.ms.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author jianghan
 * @date 2018-10-24 13:49
 */
@Service
public class UserServiceImpl implements UserService{
    private Logger logger = LoggerFactory.getLogger(UserServiceImpl.class);
    @Autowired
    private UserMapper userMapper;

    @MasterDb
    @Override
    @Transactional
    public void add(User user) {
        logger.info("add user.");
        userMapper.add(user);
    }

    @SlaveDb
    @Override
    public List<User> getList() {
        logger.info("get list.");
        return userMapper.getList();
    }
}
